// data:$('#yourformid').serialize(),// 你的formid
var async = true; // 异步
var ajaxbo = true;
// 同步调用Ajax
function sendRequestTB(requsetUrl, paramData, callback) {
	async = false;
	$(".alertLoad").parent().fadeIn();
	sendRequest(requsetUrl, paramData, callback);
	$(".alertLoad").parent().fadeOut();
	async = true;
}
// 异步调用Ajax
function sendRequest(requsetUrl, paramData, callback) {
	$.ajax({
		cache : false,
		type : "post",
		url : requsetUrl + "?timestamp=" + new Date().getTime(),
		data : paramData,
		async : async,
		success : function(data) {
			try {
				callback(data);
				return true;
			} catch (e) {
				showMSG("解析异常，请稍后再试", -1, 10);
				console.error(e);
			}
		},
		complete : function(XMLHttpRequest, status) {
			if (status != "success") {
				ajaxbo = false;
				if (status == "timeout") {
					showMSG("请求超时，请稍后再试", -1, 10);
				} else if (status == "error") {
					showMSG("系统异常，请稍后再试", -1, 10);
				}
			}
		}
	});
}
/**
 * 格式化字符串，暂支持0-99个参数替换
 */
function formatString(template, params) {
	if (params === undefined) {
		return template;
	}
	var tmpArr = [];
	for (var i = 0; i < template.length;) {
		var ch = template.charAt(i);
		if (ch === '{') {
			i++;
			var index = parseInt(template.charAt(i));
			i++;
			ch = template.charAt(i);
			if (ch != '}') {
				tmpArr.push(params[index * 10 + parseInt(template.charAt(i))]);
				i++;
			} else {
				tmpArr.push(params[index]);
			}
		} else {
			tmpArr.push(ch);
		}
		i++;
	}
	return tmpArr.join('');
}
// 安全级别
function SecurityLevel(value) {
	var NUMTEST = /[0-9]/;
	var LETTERTEST = /[a-zA-Z]/;
	var OTHERTEST = /[^a-zA-Z0-9]/;
	var hasNum = NUMTEST.test(value);
	var hasLetter = LETTERTEST.test(value);
	var hasOther = OTHERTEST.test(value);
	return hasNum ? (hasLetter ? (hasOther ? '强' : '中') : (hasOther ? '中' : '弱')) : (hasLetter ? (hasNum ? ('中') : ('弱')) : (hasOther ? ('弱') : ('')));
}
// 去除form表单 特殊字符
function baseCheckForm(form) {
	$(form).find("input").each(function() {
		var val = $.trim($(this).val());
		val = val.replace("<", "&lt;");
		val = val.replace(">", "&gt;");
		$(this).val(val);
	});
}
// 倒计时工具类
function countdown(time, AFunc, BFunc) {
	--time;
	setTimeout(function() {
		if (time > 0) {
			if (AFunc != null)
				AFunc(time);
			countdown(time, AFunc, BFunc);
		} else {
			if (BFunc != null)
				BFunc();
		}
	}, 1000);
}
// String去除空格
String.prototype.trim = function() {
	return this.replace(/(^\s*)|(\s*$)/g, "");
}

// 验证邮箱
function isEmail(str) {
	var reg = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/;
	return reg.test(str);
}
// 验证手机
function isMobile(str) {
	var reg = /^(((1[0-9]{2}))+\d{8})$/;
	return reg.test(str);
}
// 验证电话
function isPhone(str) {
	var reg = /^0\d{2,3}-?\d{7,8}$/;
	return reg.test(str);
}